(function () {
    'use strict';

    angular.module('app')
        .controller('SysDeptFormCtrl', SysDeptFormCtrl);

    SysDeptFormCtrl.$inject = ['$rootScope', '$scope', '$state', 'toaster', 'SysDeptService', 'DICT_CONST'];
    function SysDeptFormCtrl($rootScope, $scope, $state,toaster, sysDeptService, DICT_CONST) {

        $scope.title = '部门信息';
        var id = $state.params.id;
        if (!!id) { //编辑
            $scope.title = '部门详情';
            $rootScope.loading = true;
                sysDeptService.getById(id)
                .then(function (data) {
                    $scope.SysDept = data;
                })
                .finally(function () {
                    $rootScope.loading = false;
                });
        } else { //新建
            $scope.title = '新建部门';
            $scope.SysDept = {

            };
        }


        $scope.saveData = function () {
            $rootScope.loading = true;
            sysDeptService.saveData($scope.SysDept)
                .then(function () {
                    toaster.pop('success', '', '保存成功');
                })
                .finally(function () {
                    $rootScope.loading = false;
                })
            ;
        }

    }
})();